<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Broker;
use App\Models\Company;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Controllers\AdminController;

class BrokerController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {

        return Grid::make(new Broker(), function (Grid $grid) {
            $company_name=Company::CompanyData();
            $grid->column('id','序号')->sortable();
            $grid->column('true_name','姓名');
            $grid->column('phone','手机号');
            $grid->column('company_id','公司名称')->using($company_name);
            $grid->column('new_home','新房');
            $grid->column('used_home','二手房');
            $grid->column('lease_home','租房');
            $grid->column('is_quit','是否在职')->using(['0' => '在职', '1' => '离职']);
            $grid->column('state','审核状态')->select(['0' => '待审核', '1' => '未通过','2'=>'已通过']);

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id','序号');
                $filter->equal('phone','手机号');
                $filter->equal('state','状态')->select(['0' => '启用', '1' => '禁用']);
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {

        return Show::make($id, new Broker(), function (Show $show) {
            $company_name=Company::CompanyData();
            $show->field('id');
            $show->field('true_name','姓名');
            $show->field('phone','手机号');
            $show->field('sex','性别');
            $show->field('company_id','所属公司')->using($company_name);
            $show->field('new_home','新房');
            $show->field('used_home','二手房');
            $show->field('lease_home','租房');
            $show->field('is_quit','是否在职');
            $show->field('turnover');
            $show->field('state','审核状态');
            $show->field('address','详细地址');
            $show->field('avatar_url')->image();

            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Broker(), function (Form $form) {
            $company_name=Company::CompanyData();
            $form->display('id','序号');
            $form->text('true_name','姓名');
            $form->text('phone','手机号');
            $form->radio('sex','性别')->options(['0' => '女', '1' => '男']);
            $form->radio('state','审核状态')->options(['0' => '待审核', '1' => '未通过','2'=>'已通过']);
            $form->select('company_id','所属公司')->options($company_name);
            $form->distpicker([
                'province_id' => '省份',
                'city_id' => '市',
                'district_id' => '区'
            ], '地域选择')->default([
                'province' => 310000,
                'city'     => 310100,
                'district' => 310120,
            ]);
            $form->text('address','详细地址');
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}











